package com.cius.util;

import com.cius.model.PaymentWay;
import org.apache.struts2.util.StrutsTypeConverter;

import java.util.Map;

/**
 * 支付方式类型转换器
 * Created by CiusCheung on 16/9/18.
 */
public class PaymentWayConversion extends StrutsTypeConverter {
    @Override
    public Object convertFromString(Map arg0,String[] arg1,Class arg2){
        PaymentWay[] paymentWays = PaymentWay.values();
        for (PaymentWay paymentWay : paymentWays){
            if(paymentWay.getName().equals(arg1[0])){
                return paymentWay;
            }
        }
        return null;
    }
    
    @Override
    public String convertToString(Map arg0,Object arg1){
        PaymentWay paymentWay = (PaymentWay) arg1;
        return paymentWay.getName();
    }
}
